<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/jsp/commons/taglibs.jsp" %>
<script>
    $(document).ready(function () {
        //聚焦第一个输入框
        $("#name").focus();
        //为inputForm注册validate函数
        $("#inputForm").validate({
            rules: {
                gorder: "required",
                url: "required",
                type: "required",
                memo: "required",
                "group.id": {
                    number: true,
                    required: true
                },
                name: {
                    required: true,
                    remote: {
                        type: "POST",
                        url: "${ctx}/security/resources/repeat",
                        data: {
                            account: function () {
                                return $.trim($("#name").val());
                            },
                            id: ${resources.id == null ? 0:resources.id}
                        }
                    }
                }
            },
            messages: {
                name: {
                    remote: "资源名称重复"
                }
            }

        });
        $("#seeIcons").toggle(function () {
            $(".icons").show("slow");
            $(this).text("隐藏图标");
        }, function () {
            $(this).text("修改图标");
            $(".icons").hide("slow");
        });
        $(".icons span").click(function () {
            $("#icon").val($(this).find("i").attr("class"));
            $("#iconbar").attr("class", $("#icon").val());
        }).css("cursor", "pointer");
    });
</script>
<!-- content -->
<form id="inputForm" class="well form-inline" action="${ctx}/security/resources/save" method="post">
    <input type="hidden" name="id" value="${resources.id}"/>
    <table class="table table-striped table-bordered table-condensed">
        <thead>
        <strong>
            <i class="icon-flag"></i>
            资源表单
        </strong>
        </thead>
        <tr>
            <td class="span2">资源名称:</td>
            <td>
                <input id="name" name="name" type="text" value="${resources.name}" size="30" maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>URL路径:</td>
            <td>
                <input id="url" name="url" type="text" value="${resources.url}" class="span6" maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>图标:</td>
            <td>
                <input id="icon" readonly="readonly" name="icon" type="hidden"
                       value="${resources.icon == null ? 'icon-list-alt':resources.icon}" size="30" maxlength="80"/>
                <i id="iconbar" class="${resources.icon == null ? 'icon-list-alt':resources.icon}"></i>
                <a id="seeIcons" style="cursor: pointer;" deny="not">修改图标</a>

                <div>
                    <%@ include file="/WEB-INF/html/frame/icons.html" %>
                </div>
            </td>
        </tr>
        <tr>
            <td>资源组:</td>
            <td>
                <select id="group" name="group.id">
                    <c:forEach var="group" items="${groupList}">
                        <option value="${group.id }" <c:if
                                test="${resources.group.id == group.id}"> selected="selected" </c:if>>${group.name }</option>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr>
            <td>菜单:</td>
            <td>
                <label class="radio">
                    <input name="menu" type="radio" value="1"
                           <c:if test="${resources.menu}">checked="checked"    </c:if> />
                    是
                </label>
                <label class="radio">
                    <input name="menu" type="radio" value="0"
                           <c:if test="${!resources.menu}">checked="checked"    </c:if> />
                    否
                </label>
            </td>
        </tr>
        <tr>
            <td>组内排序:</td>
            <td>
                <input id="gorder" name="gorder" type="text" value="${resources.gorder}" size="30" maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>备注:</td>
            <td>
                <textarea id="memo" name="memo" rows="4" class="span6">${resources.memo}</textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input class="btn" type="submit" value="提交"/>
                &nbsp;
                <input class="btn" type="button" value="返回" back="back"/>
            </td>
        </tr>
    </table>
</form>
